package com.cjq.mall.wallet.controller;

import com.cjq.mall.wallet.pojo.dto.WalletDTO;
import com.cjq.mall.wallet.pojo.dto.WalletRefundDTO;
import com.cjq.mall.wallet.pojo.vo.BusinessDetailVO;
import com.cjq.mall.wallet.pojo.vo.WalletVO;
import com.cjq.mall.wallet.service.WalletService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/wallet")
@Api(tags = "钱包交易模块")
public class WalletController {

    @Autowired
    private WalletService walletService;

    @GetMapping("/get")
    @ApiOperation("根据用户id查询用户钱包余额")
    @ApiImplicitParam(value = "用户id", name = "userId", example = "1")
    public WalletVO getWallet(Long userId){
        WalletVO walletVO = walletService.getWallet(userId);

        return walletVO;
    }

    @PostMapping("/consume")
    @ApiOperation("减少用户钱包余额")
    public String consume(WalletDTO walletDTO){
        walletService.consume(walletDTO);

        return "消费完成！";
    }

    @PostMapping("/refund")
    @ApiOperation("退款")
    public String refund(WalletRefundDTO walletRefundDTO){
        walletService.refund(walletRefundDTO);

        return "退款完成！";
    }

    @GetMapping("/list")
    @ApiOperation("根据用户id查询交易明细")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户id", name = "userId", example = "1"),
            @ApiImplicitParam(value = "要查询多少个月内的交易明细", name = "months", example = "1"),
            @ApiImplicitParam(value = "页码", name = "page", example = "1"),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", example = "10")
    })
    public PageInfo<BusinessDetailVO> getBusinessDetail(Long userId, Integer months, Integer page, Integer pageSize){
        PageInfo<BusinessDetailVO> pageInfo = walletService.getBusinessDetail(userId, months, page, pageSize);
        return pageInfo;
    }
}
